package com.njwb.selector;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class SpringBootImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        List<String> classNames = new ArrayList<String>();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(SpringBootImportSelector.class.getClassLoader()
                    .getResourceAsStream("bean.imports")));
            String className = br.readLine();
            while(className != null){
                classNames.add(className);
                className = br.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null != br){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        //返回所有需要被导入的类的包名全路径
//        return new String[]{"cn.njwb.config.BussinessConfig"};
        return classNames.toArray(new String[classNames.size()]);
    }
}
